package com.wasu.service;

import java.util.ArrayList;
import java.util.List;

import org.joda.time.LocalDate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wasu.bean.AdSchedule;
import com.wasu.bean.RunResult;

@Controller
@RequestMapping("/order")
public class OrderRunResult{

	@ResponseBody
	@RequestMapping("/queryresult")
	public List<RunResult> queryresult() {
		List<RunResult> list  = new ArrayList<RunResult>();
		LocalDate  date = new LocalDate();
		List<String> orders = OrderJedis.getValues(date.toString());
		int unrun =0;
		for(String adcode: orders){
			RunResult  result = new RunResult();
			result.setAdcode(adcode);
			AdSchedule adSchedule = OrderJedis.readSchedules(adcode+"_"+date.toString()+"_done");
			if(adSchedule!=null){
				result.setDayevt(adSchedule.getDayevt());
				result.setDayev1(adSchedule.getDayev1());
				result.setExpectsize(OrderJedis.getKeyLen(adcode+"_"+date.toString()+"_DATA"));
				result.setIsrun(true);
				result.setStarttime(adSchedule.getStarttime());
//				result.setUsercounts(adSchedule.getEndLine()-adSchedule.getStartLine()+adSchedule.getRepeat());
				
			}else{
				unrun++;
				result.setDayevt(0);
				result.setDayev1(0);
				result.setIsrun(false);
			}
			list.add(result);
		}		
		
		for(RunResult rr :list){
			rr.setUnrun(unrun);
		}
		
		return list;
	}
}
